import React, {Component} from 'react'
import {ListComponent} from '../../../components'
import { Form } from 'antd';
import ControlForm from './ControlForm'
const WrappedControlForm = Form.create()(ControlForm);

export default class Control extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            rowObj: {},
            isAdd: true
        };
        //行操作列表
        this.rowOperation = [
            {
                handleName: 'rowClick',
                showName: '行单击选择事件'
            }
        ];
        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏（用于列配置显示隐藏）, foreverHidden: true 列永久隐藏
        this.tableColumn = {
            data: [
                {
                    showName: 'productControlId',
                    columnName: 'productControlId',
                    columnHidden:true,
                    foreverHidden: true
                },{
                    showName: '仓库编码',
                    columnName: 'whCode'
                },{
                    showName: '客户编码',
                    columnName: 'custCode'
                },{
                    showName: '产品编码',
                    columnName: 'productCode'
                },{
                    showName: '包装代码',
                    columnName: 'packageCode'
                },{
                    showName: '产品仓储类型',
                    columnName: 'productTypeCode'
                },{
                    showName: '危险品标识',
                    columnName: 'dangerFlag'
                },{
                    showName: '存储环境',
                    columnName: 'storageEnv'
                },{
                    showName: '收货方式',
                    columnName: 'takeGoodsWay'
                },{
                    showName: '批次属性',
                    columnName: 'batchCode'
                },{
                    showName: '库位指定规则',
                    columnName: 'locAssignWay'
                },{
                    showName: '上架规则',
                    columnName: 'shelfRule'
                },{
                    showName: '上架库位',
                    columnName: 'shelfLoc'
                },{
                    showName: '库存周转天数',
                    columnName: 'stockTurnDays'
                },{
                    showName: '分配规则',
                    columnName: 'distributeRule'
                },{
                    showName: '有效期控制',
                    columnName: 'validDateControl'
                },{
                    showName: '有效期天数',
                    columnName: 'validDate'
                },{
                    showName: '有效期类型',
                    columnName: 'validDateType'
                },{
                    showName: '失效期预警',
                    columnName: 'expiryDateWarn'
                },{
                    showName: '入库效期',
                    columnName: 'instockPeriod'
                },{
                    showName: '出库效期',
                    columnName: 'outstockPeriod'
                },{
                    showName: '是否冻结',
                    columnName: 'freezeFlag'
                },{
                    showName: '质检周期',
                    columnName: 'qcCycle'
                },{
                    showName: '创建人',
                    columnName: 'createBy'
                },{
                    showName: '创建时间',
                    columnName: 'gmtCreateStr'
                },{
                    showName: '更新人',
                    columnName: 'lastModifiedBy'
                },{
                    showName: '更新时间',
                    columnName: 'gmtModified'
                }
            ]
        };
    }
    rowHandles = (strHandles, rowObj) => {
        if(strHandles == 'rowClick'){
            this.rowClickHandle(rowObj);
        }
    }

    rowClickHandle = (rowObj) => {
        if(rowObj.length == 0){
            this.setState({ rowObj: {}, isAdd: true });
        }else{
            this.setState({ rowObj: rowObj[0].data, isAdd: false });
        }
    }
    refreshHandle = () => {
        this.refs.listComponent.refreshHandle();
    }

    render() {
        return (
            <div>
                <ListComponent
                    ref = "listComponent"
                    url = {this.props.url}
                    searchCondition={this.props.searchCondition}
                    tableColumnData = {this.tableColumn}
                    rowOperation = {this.rowOperation}
                    rowHandles = {this.rowHandles}
                    isRowSingle = "true"
                    subtractHeight='0'
                    subtractWidth='145'
                />

                <WrappedControlForm
                    refreshHandle = {this.refreshHandle}
                    searchCondition={this.props.searchCondition}
                    rowObject={this.state.rowObj}
                    isAdd={this.state.isAdd}
                />
            </div>
        );
    }
}
